package com.hfh.work;

import com.hfh.test.SellTickets;

/**
 * @Author hfh
 * @Date 2022 09 15 17 14
 **/
public class SellTicket implements Runnable{
    private int num = 100;

    public static void main(String[] args) {
        SellTicket st = new SellTicket();
        for (int i = 1;i<=5;i++){
            new Thread(st,"窗口"+i+":").start();
        }
    }

    @Override
    public void run() {

           while (num>0){
               synchronized (this) {
                   if(num>0){
                       System.out.println(Thread.currentThread().getName() + "卖了第" + num-- + "张票");
                   }
               }
            }
    }
}
